package com.hzp.lolnews.ui.novel.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.R;
import com.hzp.lolnews.base.BaseRecyclerViewHolder;
import com.hzp.lolnews.ui.novel.bean.FridBean;
import com.hzp.lolnews.ui.novel.view.DetailShopActivity;

import java.util.List;

/**
 * Created by Administrator on 10/21 0021.
 */
public class FridAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {

    private List<FridBean.DataBean.RowsBean> mList;
    private Context mContext;
    private View view;

    public void setData(List<FridBean.DataBean.RowsBean> List) {
        for (int i = 0; i < List.size(); i++) {
            if (List.get(i).getPromotion_type()=="1") {
                List.remove(i);
                break;
            }
        }
        this.mList = List;
        notifyDataSetChanged();
    }
    public void setMoreData(List<FridBean.DataBean.RowsBean> list){
        mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.frid_list_item, parent, false);
        return new BaseRecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder holder, final int position) {
        final FridBean.DataBean.RowsBean homeContent = mList.get(position);
        String type = homeContent.getPromotion_type();
        Log.i("TAC",type);
        if(type.equals("1")){
            LinearLayout ll = (LinearLayout)view.findViewById(R.id.frid_view);
            ll.setVisibility(View.GONE);
        }else {
            holder.getView(R.id.frid_view).setVisibility(View.VISIBLE);
            SimpleDraweeView simpleDraweeView = holder.getView(R.id.frid_simpleDraweeView);
            simpleDraweeView.setImageURI(homeContent.getArticle_pic());
            TextView tvPin = holder.getView(R.id.frid_tvPin);
            tvPin.setText(homeContent.getArticle_comment());
            TextView tvSource = holder.getView(R.id.frid_tvSource);
            tvSource.setText(homeContent.getArticle_mall());
            TextView tvTime = holder.getView(R.id.frid_tvTime);
            tvTime.setText(homeContent.getArticle_format_date());
            TextView tvTitle = holder.getView(R.id.frid_tvTitle);
            tvTitle.setText(homeContent.getArticle_title());
            TextView tvPrice = holder.getView(R.id.frid_tvPrice);
            tvPrice.setText(homeContent.getArticle_price());
            TextView tvZhi = holder.getView(R.id.frid_tvZhi);
            tvZhi.setText(homeContent.getArticle_worthy());
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mContext, DetailShopActivity.class);
                    intent.putExtra("getArticle_pic",homeContent.getArticle_pic());
                    intent.putExtra("getArticle_type_name",homeContent.getArticle_type_name());
                    intent.putExtra("getArticle_format_date",homeContent.getArticle_format_date());
                    intent.putExtra("getArticle_title",homeContent.getArticle_title());
                    intent.putExtra("getArticle_price",homeContent.getArticle_price());
                    mContext.startActivity(intent);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }
}
